<template>
  <z-modal title="编辑" :visible="visible" :loading="loading" @onConfirm="onConfirm">
    <z-form :inputs="inputs" ref="form"></z-form>
  </z-modal>
</template>

<script>
import ZModal from "@/components/ZBase/ZModal.vue";
import ZForm from "@/components/ZForm/ZForm.vue";
export default {
  props: {
    row: {
      type: Object,
      default: () => {},
    },
  },
  components: {
    ZModal,
    ZForm,
  },
  data() {
    return {
      visible: false,
      loading: false,
      inputs: [],
    };
  },
  onCreateApi() {
    this.visible = true;
    this.inputs = this.getInputs(this.row);
  },
  methods: {
    getInputs(data) {
      return [
        {
          label: "姓名",
          name: "Cname",
          type: "text",
          value: data?.Cname,
          rules: [{ required: true, message: "请填入姓名" }],
        },
        {
          label: "年级",
          name: "grade",
          type: "select",
          value: data?.grade,
          rules: [{ required: true, message: "请选择" }],
          options: [
            { lable: "高一", value: "高一" },
            { lable: "高二", value: "高二" },
          ],
        },
        {
          label: "语文",
          name: "chinese",
          type: "number",
          max: 120,
          value: data?.chinese,
          rules: [{ required: true, message: "请填入语文分数" }],
        },
        {
          label: "数学",
          name: "mathematics",
          type: "number",
          value: data?.mathematics,
          max: 120,
          rules: [{ required: true, message: "请填入数学分数" }],
        },
        {
          label: "英语",
          name: "english",
          type: "number",
          max: 120,
          value: data?.english,
          rules: [{ required: true, message: "请填入英语分数" }],
        },
      ];
    },
    async onConfirm() {
      await this.$refs.form.validate();
      this.loading = true;
      setTimeout(() => {
        this.visible = false;
        this.loading = false;
      }, 1000);
    },
  },
};
</script>

<style lang="scss" scoped></style>
